<template>
  <div id="yhzz">
    <header class="header">
      <div class="title">
        <img
          src="../../assets/images/01_11.png"
          alt=""
          class="img_zuo"
          @click="back"
        />
        <div v-show="yhzz_params.cx_type == 'xqda'">
          <span v-show="yhzz_params.type === 1">九小门店</span>
          <span v-show="yhzz_params.type === 2">建筑物</span>
          <span v-show="yhzz_params.type === 3">住改非</span>
          <span v-show="yhzz_params.type === 4">企业</span>
          <span v-show="yhzz_params.type === 5">其它</span>
        </div>
        <div v-show="yhzz_params.cx_type == 'yhlb'">
          <span v-show="yhzz_params.type === 1">限期整改</span>
          <span v-show="yhzz_params.type === 2">即查即改</span>
          <span v-show="yhzz_params.type === 3">落实管控</span>
        </div>
        <div v-show="yhzz_params.cx_type == 'yhzz'">
          <span v-show="yhzz_params.type === 2">已整改</span>
          <span v-show="yhzz_params.type === 3">落实管控</span>
          <span v-show="yhzz_params.type === 4">未整改</span>
        </div>
      </div>
    </header>

    <div class="contant">
      <!--<van-pull-refresh v-model="refreshing" @refresh="onRefresh">-->
      <van-list v-model="loading" :finished="finished" @load="onLoad">
        <div
          class="box_list"
          v-for="(item, index) of list"
          :key="index"
          @click="detail(item)"
        >
          <!--<img class="img_logo7" src="../../assets/images/logo7.png" />-->
          <img class="img_logo5" src="../../assets/images/logo5.png" />
          <div class="center">
            <div class="left">
              <div class="small_title">
                [{{ item.broadHeadingName }}]{{ item.unitsName }}
              </div>
              <div class="introduce">
                <div class="intro_name">
                  <img
                    class="yh_light"
                    v-show="getStatus(item) == '黄灯'"
                    src="../../assets/images/jsd.gif"
                  />
                  <img
                    class="yh_light"
                    v-show="getStatus(item) == '勾'"
                    src="../../assets/images/lg.png"
                  />
                  <img src="../../assets/images/people.png" />
                  <div v-if="yhzz_params.cx_type == 'yhzz'">
                    {{ item.userName }}
                  </div>
                  <div v-if="yhzz_params.cx_type != 'yhzz'">
                    {{ item.ptPerson }}
                  </div>
                </div>
              </div>
            </div>
            <div class="right">
              <div class="data" v-if="yhzz_params.cx_type == 'yhzz'">
                {{ getTime(item.addTime) }}
              </div>
              <div class="data" v-if="yhzz_params.cx_type != 'yhzz'">
                {{ item.niAddtime }}
              </div>
            </div>
          </div>
        </div>
      </van-list>
      <!--</van-pull-refresh>-->
    </div>
  </div>
</template>

<script>
import utils from "../../assets/js/utils.js";
export default {
  name: "yhzz_list",
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      page: 1,
      pageSize: 50,
      jdnum: "",
      load_over: false,
      userId: null, //用户id
      yhzz_params: {},
    };
  },
  methods: {
    back() {
      // if(this.yhzz_params.from){
      //   this.$router.push(this.yhzz_params.from);
      // }else{
      //   this.$router.push("/index");
      // }
      this.$router.back();
    },
    onLoad() {
      var _this = this;
      if (_this.refreshing) {
        _this.list = [];
        _this.refreshing = false;
        _this.page = 1;
      }

      /*try{
            plus.nativeUI.showWaiting("正在加载...");
          }catch(e){
            console.log(e.message);
          }*/

      var url = "";
      var params = null;
      var quanxian = sessionStorage.getItem("shequname");
      var benjishequ = localStorage.getItem("yhzz")
        ? JSON.parse(localStorage.getItem("yhzz"))
        : {};
      var xzrid = localStorage.getItem("yhzz_keshi")
        ? JSON.parse(localStorage.getItem("yhzz_keshi"))
        : {};
      this.jdnum = sessionStorage.getItem("jdnum");
      var time = sessionStorage.getItem("time")
        ? JSON.parse(sessionStorage.getItem("time"))
        : {};
      var qx = localStorage.getItem("yhzz_quanxian")
        ? JSON.parse(localStorage.getItem("yhzz_quanxian"))
        : {};

      console.log(qx);
      if (_this.yhzz_params.cx_type == "xqda") {
        params = {
          userId: _this.userId,
          type: _this.yhzz_params.type, //type 1九小 2建筑物 3住改非
          page: _this.page,
          pageSize: _this.pageSize,
          year: time.years,
          month: time.year,
        };
      

        if (qx == 0) {
          console.log(0);
          if (quanxian == "街道本级" || quanxian == "社区本级") {
            params.isBenji = 2;
            params.status = _this.jdnum;
               params.dwId = _this.yhzz_params.sqid;
          } else {
            if (localStorage.getItem("btn") == 0) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 1) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 2) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 3) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
              params.status = _this.jdnum;
            }
          }
        }
         if (qx == 1||qx == 3) {
          console.log(1);
          if (quanxian == "街道本级" || quanxian == "社区本级") {
            params.isBenji = 2;
            params.status = _this.jdnum;
                params.dwId = _this.yhzz_params.sqid;
          } else {
            if (localStorage.getItem("btn") == 0) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 1) {
              params.isBenji = sessionStorage.getItem("isbenji");
            params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 2) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 3) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
              params.status = _this.jdnum;
            }
          }
        }
  if (qx == 2) {
          console.log(2);
          if (quanxian == "街道本级" || quanxian == "社区本级") {
            params.dwId = _this.yhzz_params.sqid;

            params.status = _this.jdnum;
          } else {
            params.dwId = "";
          }
        } 
        // else {
        //   params.dwId = _this.yhzz_params.sqid;
        // }

        url = "/remediaHiddenDangers/dangerStatistics";
      } else if (_this.yhzz_params.cx_type == "yhlb") {
        params = {
          userId: _this.userId,
          type: _this.yhzz_params.type, //type 1限期 2即查即改 3监管
          page: _this.page,
          pageSize: _this.pageSize,
      
          year: time.years,
          month: time.year,
        };
        
        if (qx == 0) {
          console.log(0);
          if (quanxian == "街道本级" || quanxian == "社区本级") {
            params.isBenji = 2;
            params.status = _this.jdnum;
   params.dwId = _this.yhzz_params.sqid;
          } else {
            if (localStorage.getItem("btn") == 0) {
              params.isBenji = sessionStorage.getItem("isbenji");
            
            } else if (localStorage.getItem("btn") == 1) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 2) {
              params.isBenji = sessionStorage.getItem("isbenji");
              params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 3) {
              params.isBenji = sessionStorage.getItem("isbenji");
               params.dwId = _this.yhzz_params.sqid;
              params.status = _this.jdnum;
            }
          }
        }

          if (qx == 1||qx == 3) {
          console.log(1);
          if (quanxian == "街道本级" || quanxian == "社区本级") {
            params.isBenji = 2;
            params.status = _this.jdnum;
          } else {
               if (localStorage.getItem("btn") == 0) {
              params.isBenji = sessionStorage.getItem("isbenji");
              params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 1) {
              params.isBenji = sessionStorage.getItem("isbenji");
                params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 2) {
              params.isBenji = sessionStorage.getItem("isbenji");
              params.dwId = _this.yhzz_params.sqid;
            } else if (localStorage.getItem("btn") == 3) {
              params.isBenji = sessionStorage.getItem("isbenji");
                 params.dwId = _this.yhzz_params.sqid;
              params.status = _this.jdnum;
            }
          
          }
        }
        if (qx == 2) {
          if (quanxian == "街道本级" || quanxian == "社区本级") {
            params.dwId = _this.yhzz_params.sqid;
            params.status = _this.jdnum;
          } else {
            params.dwId = "";
          }
        }
       if (localStorage.getItem("yhzz_quanxian") == 5||localStorage.getItem("yhzz_quanxian") == 4) {
          params.dwId = "";
        } 
        // else {
        //   params.dwId = benjishequ.shequid;
        // }
        url = "/remediaHiddenDangers/dangerYhlb";
      } else if (_this.yhzz_params.cx_type == "yhzz") {
        params = {
          sqId: _this.yhzz_params.sqid,
          type: _this.yhzz_params.type, //type 1限期 2即查即改 3监管
          isBenji: sessionStorage.getItem("isbenji"),
          year: time.years,
          month: time.year,
          userId: _this.userId,
        };
        // if (quanxian == "街道本级" || quanxian == "社区本级") {
        //   params.status = _this.jdnum;
        // }
        url = "/DwSelectList";
      } else if (_this.yhzz_params.cx_type == "keshi") {
        params = {
          userId: xzrid,
          page: _this.page,
          pageSize: _this.pageSize,
          year: time.years,
          month: time.year,
          operatorId: _this.userId,
        };
        if (quanxian == "街道本级" || quanxian == "社区本级") {
         params.status = _this.jdnum;
        } else {
           params.status = _this.jdnum;
        }
        if (localStorage.getItem("yhzz_quanxian") == 5||localStorage.getItem("yhzz_quanxian") == 4) {
          params.dwId = "";
        } else {
          params.dwId = benjishequ.shequid;
        }
        url = "/remediaHiddenDangers/peopleList";
      } else {
        _this.loading = false;
        return;
      }

      _this.axios
        .get(_this.$global_msg.Url.host + url, {
          params: params,
        })
        .then(function (data) {
          console.log("接口返回:", data);
          if (data && data.data) {
            if (_this.yhzz_params.cx_type == "yhzz") {
              if (data.data.list && data.data.list.length > 0) {
                _this.list = data.data.list;
              } else {
                _this.list = [];
              }
              _this.finished = true;
            } else {
              if (data.data.code == 200) {
                if (data.data.rows && data.data.rows.list) {
                  _this.list = _this.list.concat(data.data.rows.list);
                }
                if (_this.list.length >= data.data.rows.total) {
                  _this.finished = true;
                } else {
                  _this.page++;
                }
              } else {
                _this.$toast(data.data.msg);
                _this.finished = true;
              }
            }
          } else {
            _this.$toast("查询失败");
          }
          _this.loading = false;
          _this.load_over = true;

          try {
            plus.nativeUI.closeWaiting();
          } catch (e) {
            console.log(e.message);
          }
        })
        .catch((error) => {
          _this.$terminal._error(error);
        });
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    getStatus(item) {
      var status = null;
      var str = "";
      if (item.patrolTroubleshootId > 0) {
        status = item.isRectifica;
        if (status || status === 0) {
          if (status === 1 || status === 3 || status === 6) {
            str = "勾";
          } else {
            str = "黄灯";
          }
        }
      } else {
        status = item.status;
        if (status || status === 0) {
          if (status === 1 || status === 3 || status === 99) {
            str = "勾";
          } else if (status === 0) {
            str = "黄灯";
          }
        }
      }

      return str;
    },
    getTime(time) {
      return utils.dateFormat(time, "MM-DD");
    },
    detail(item) {
      if (item.patrolTroubleshootId > 0) {
        localStorage.setItem("yh_list_scrollTop", $(".contant").scrollTop());
        var isBenji =
          this.yhzz_params.isBenji || this.yhzz_params.isBenji === 0
            ? this.yhzz_params.isBenji
            : "";
        localStorage.setItem("yh_detail_isBenji", isBenji);
        localStorage.setItem(
          "yh_detail_patrolTroubleshootId",
          JSON.stringify(item.patrolTroubleshootId)
        );
        localStorage.setItem(
          "yh_detail_patrolTroubleshootInfoId",
          JSON.stringify(item.patrolTroubleshootInfoId)
        );
        localStorage.setItem("yh_detail_from", "/yhzz_list");
        this.$router.push("/yhzz_detail");
      } else {
        this.$router.push({
          path: "/ptlook",
          query: { id: item.noweInfoId, ids: 14, isYh: true },
        });
      }
    },
  },
  //进入该页面时，用之前保存的滚动位置赋值
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      var yh_list_scrollTop = localStorage.getItem("yh_list_scrollTop");
      if (yh_list_scrollTop || yh_list_scrollTop === 0) {
        $(".contant").animate({ scrollTop: yh_list_scrollTop }, 0);
      } else {
        vm.userId = localStorage.getItem("userId"); //用户id

        vm.yhzz_params = localStorage.getItem("yhzz_params")
          ? JSON.parse(localStorage.getItem("yhzz_params"))
          : {};
        if (vm.load_over) {
          vm.list = [];
          vm.refreshing = false;
          vm.page = 1;
          vm.onRefresh();
        }
      }
      localStorage.removeItem("yh_list_scrollTop");
      localStorage.removeItem("yh_detail_patrolTroubleshootId");
      localStorage.removeItem("yh_detail_patrolTroubleshootInfoId");
      localStorage.removeItem("yh_detail_isBenji");
    });
  },
  mounted() {
    var _this = this;
    //物理返回
    // window.addEventListener("popstate", function(){
    //   _this.back();
    // }, false);
  },
};
</script>

<style scoped>
.img_logo5 {
  width: 0.6667rem;
  height: 0.7407rem;
  margin: 0 0.3rem;
}
.img_logo7 {
  width: 0.805555rem;
  height: 0.759259rem;
  margin: 0 0.3rem;
}
.img_logo5 {
  width: 0.666666rem;
  height: 0.74074rem;
  margin: 0 0.3rem;
}

.center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 0.2778rem;
  padding-top: 0.1rem;
}

.intro_name {
  display: flex;
  align-items: center;
}

.intro_name img {
  width: 0.2963rem;
  margin-right: 0.1852rem;
}
.intro_name div {
  font-size: 0.2963rem;
}

.introduce {
  display: flex;
  width: 100%;
  color: #8e8e8e;
  font-size: 0.3148rem;
  align-items: center;
  margin-top: 0.0926rem;
}

.small_title {
  font-size: 0.4rem;
  width: 6.5rem;
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.contant {
  width: 100%;
  flex: 1;
  overflow-y: scroll;
  padding-top: 0.185185rem;
  padding-bottom: 0.185185rem;
}
.box_list {
  display: flex;
  align-items: center;
  height: 1.3889rem;
  background-color: white;
  border-radius: 0.2rem;
}
.box_list .left {
  flex: 1;
  height: 100%;
}
.box_list .right {
  width: 1.5rem;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.box_list .data {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
/* 头部 */
.header {
  height: 1.8519rem;
  background: #007aff;
  padding-top: 0.8333rem;
  box-sizing: border-box;
  /*position: fixed;*/
  width: 100%;
  /*top: 0;*/
  z-index: 20;
  font-size: 0.388888rem;
}

.title {
  padding: 0 0.3704rem;
  display: flex;
  align-items: center;
  color: #fff;
}

.title > div {
  width: 100%;
  font-size: 0.4444rem;
  text-align: center;
}

.img_zuo {
  width: 0.2593rem;
  height: 0.463rem;
}

#yhzz {
  width: 100%;
  height: 100%;
  background-color: #f7f7f9;
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
}

.yh_light {
  width: 0.37037rem !important;
  height: 0.37037rem !important;
}
</style>
